Explain the concept of include and extends in consideration with use case scenario with example.
Β«IncludeΒ» and Β«ExtendΒ» Relationships in Use Case Diagramsβ
In UML use case modeling, the Β«includeΒ» and Β«extendΒ» relationships are important concepts that help manage complexity and reduce redundancy in use case diagrams by showing how use cases relate to each other.
The Β«IncludeΒ» Relationshipβ
The Β«includeΒ» relationship indicates that a base use case explicitly incorporates the behavior of another use case at a specific location in its sequence. It represents mandatory behavior - the included use case will always be executed when the base use case is performed.
Key Characteristics of Β«IncludeΒ»:β
- Mandatory Execution: The included use case is always executed when the base use case runs
- Reuse of Functionality: Helps avoid duplication by extracting common behavior into separate use cases
- Simplification: Makes complex use cases more manageable by breaking them into smaller parts
- Direction: The arrow points from the base use case to the included use case
- Notation: Represented as a dashed arrow with the stereotype Β«includeΒ»
Example of Β«IncludeΒ» Relationship:β
In an online banking system:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Online Banking System β
β β
β ββββββββββββββββ Β«includeΒ» ββββββββββββββ β
β β βββββββββββββββββββββββΊ β β β
β β Transfer β β Verify β β
β β Funds β β User β β
β β β β β β
β ββββββββββββββββ ββββββββββββββ β
β β
β ββββββββββββββββ Β«includeΒ» β
β β βββββββββββββββββββββββ β
β β Pay Bills β β β
β β β β β
β ββββββββββββββββ βΌ β
β ββββββββββββββ β
β β β β
β β Log β β
β β Transactionβ β
β β β β
β ββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
In this example:
- Both "Transfer Funds" and "Pay Bills" include "Verify User" - User verification is a mandatory part of performing these operations
- "Pay Bills" also includes "Log Transaction" - Transaction logging is always performed when paying bills
The Β«ExtendΒ» Relationshipβ
The Β«extendΒ» relationship indicates that a base use case may be augmented by another use case under specific conditions. It represents optional behavior that may or may not occur, depending on certain conditions.
Key Characteristics of Β«ExtendΒ»:β
- Conditional Execution: The extending use case is only executed if specific conditions are met
- Optional Behavior: Represents behavior that may not always occur
- Extension Points: Defines where in the base use case the extension may be inserted
- Direction: The arrow points from the extending use case to the base use case
- Notation: Represented as a dashed arrow with the stereotype Β«extendΒ»
Example of Β«ExtendΒ» Relationship:β
In an e-commerce system:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β E-Commerce System β
β β
β ββββββββββββββββββ ββββββββββββββββββ β
β β β Β«extendΒ» β β β
β β Checkout ββββββββββββββββββββ€ Apply Discount β β
β β β β β β
β β Extension points: β β β
β β - Calculate total ββββββββββββββββββ β
β ββββββββββββββββββ β
β β
β β
β ββββββββββββββββββ ββββββββββββββββββ β
β β β Β«extendΒ» β β β
β β Process ββββββββββββββββββββ€ Verify Credit β β
β β Payment β β Card β β
β β β β β β
β β Extension points: ββββββββββββββββββ β
β β - Payment method β
β ββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
In this example:
- "Apply Discount" extends "Checkout" - Discounts are only applied if the customer has a valid discount code
- "Verify Credit Card" extends "Process Payment" - Credit card verification only occurs if the customer chooses to pay by credit card
Comparing Β«IncludeΒ» and Β«ExtendΒ» Relationshipsβ
Aspect | Β«IncludeΒ» | Β«ExtendΒ» |
---|---|---|
Nature | Mandatory behavior | Optional behavior |
Direction | Base use case β included use case | Extending use case β base use case |
Purpose | Reuse common functionality | Add optional behavior |
Execution | Always executed | Executed only if conditions are met |
Control | Base use case controls when included use case executes | Base use case may be unaware of extension |
Usage | Extract common functionality | Handle alternative flows and exceptions |
When to Use Each Relationshipβ
Use Β«IncludeΒ» when:β
- The same functionality appears in multiple use cases
- A complex use case needs to be broken down into more manageable parts
- You want to explicitly show that a certain functionality is always performed
Use Β«ExtendΒ» when:β
- Behavior is optional and occurs only under certain conditions
- You want to separate exceptional or alternative flows from the main use case
- Additional functionality might be added to a use case without modifying it
Both relationships help in creating more modular, maintainable use case models that accurately represent the behavior of complex systems while remaining understandable to stakeholders.